package com.ruoyi.bath.consumer.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


import com.ruoyi.bath.consumer.domain.Pay;
import com.ruoyi.bath.consumer.mapper.payMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import com.ruoyi.bath.consumer.mapper.ConsumerMapper;
import com.ruoyi.bath.consumer.domain.Consumer;
import com.ruoyi.bath.consumer.service.IConsumerService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 会员信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-08-07
 */
@Service
public class ConsumerServiceImpl implements IConsumerService 
{

    @Autowired
    private ConsumerMapper consumerMapper;

    /**
     * 查询会员信息
     * 
     * @param id 会员信息主键
     * @return 会员信息
     */
    @Override
    public Consumer selectConsumerById(Long id)
    {
        return consumerMapper.selectConsumerById(id);
    }

    /**
     * 查询会员信息列表
     * 
     * @param consumer 会员信息
     * @return 会员信息
     */
    @Override
    public List<Consumer> selectConsumerList(Consumer consumer)
    {
        return consumerMapper.selectConsumerList(consumer);
    }



@Autowired
@Qualifier("payMapper")
private payMapper payMapper;
    /**
     * 新增会员信息
     * 
     * @param consumer 会员信息
     * @return 结果
     */
    @Transactional
    @Override
    public int insertConsumer(Consumer consumer)
    {
        Pay pay=new Pay();
        int insertConsumer = consumerMapper.insertConsumer(consumer);
        String consumerName = consumer.getConsumerName();
        pay.setCName(consumerName);
        if(pay.getCName()!=null){
            pay.setPayPrice(consumer.getPrice());
        }
        payMapper.insert(pay);

        return insertConsumer;
    }

    /**
     * 修改会员信息
     * 
     * @param consumer 会员信息
     * @return 结果
     */
    @Override
    public int updateConsumer(Consumer consumer)
    {
        return consumerMapper.updateConsumer(consumer);
    }

    /**
     * 批量删除会员信息
     * 
     * @param ids 需要删除的会员信息主键
     * @return 结果
     */
    @Override
    public int deleteConsumerByIds(Long[] ids)
    {
        return consumerMapper.deleteConsumerByIds(ids);
    }

    /**
     * 删除会员信息信息
     * 
     * @param id 会员信息主键
     * @return 结果
     */
    @Override
    public int deleteConsumerById(Long id)
    {
        return consumerMapper.deleteConsumerById(id);
    }
//增加次数
    @Override
    public void updateCount(Consumer consumer) {
        consumerMapper.updateCount(consumer);
        System.out.println("分隔---------------------");
        System.out.println(consumer.getConsumerTimes());
        System.out.println(consumer);
        System.out.println("分隔---------------------");
      Pay pay1=new Pay();
      pay1.setCName(consumer.getConsumerName());
        System.out.println("分隔-------------------");
        System.out.println(pay1);
        System.out.println("分隔-------------------");
      if (pay1.getCName()!=null){
          pay1.setPayPrice(consumer.getPrice());
      }
      payMapper.insertPayPrice(pay1);
    }

}
